package com.grudesign.stutrip.controller;


import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.StutriprecordsPo;
import com.grudesign.stutrip.service.StutriprecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 研学游记表 前端控制器
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/stutriprecords")
public class StutriprecordsController {

    @Autowired
    private StutriprecordsService stutriprecordsService;



    @PostMapping("/getStuTrip/{cur}/{li}")
    public Object getStuTrip(@PathVariable String cur,
                               @PathVariable String li){
        Object obj =  stutriprecordsService.getStuTrips(cur,li);
        return obj;
    }


    @PostMapping("/getStuTrips/{cur}/{li}")
    public Object getStuTripes(@PathVariable String cur,
                             @PathVariable String li,
                             @RequestBody(required =false) StutriprecordsPo po){
        Object obj =  stutriprecordsService.getStutrip(cur,li,po);
        return obj;
    }

    @PostMapping("/addStuTrip")
    public Object addStuTrip(@RequestBody StutriprecordsPo stuPo){
        boolean save = stutriprecordsService.save(stuPo);
        return save?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }

    @PutMapping("/editStuTrip")
    public Object editStuTrip(@RequestBody StutriprecordsPo stuPo){
        boolean edit = stutriprecordsService.updateById(stuPo);
        return edit?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
    @DeleteMapping("/{id}")
    public  Object delStuTrip(@PathVariable String id){
        boolean isDel = stutriprecordsService.removeById(id);
        return isDel?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }

    @GetMapping("/frontRecords")
    public Object frontRecords(){
       Object obj =   stutriprecordsService.getRecords();
       return obj;
    }
}

